"use strict";
require("test").setup();

var Coroutine = require('coroutine');
var hash = require('hash');

var str_prefix = "ZG";

describe("config", function() {
    before(function() {

    });

    after(function() {
         clearDB();
    });


    it("登录", function() {
        httpPost("GET", "/v1.0/api/user/Sync", {})

        var t = "123"
        var result = httpPost("POST", "/v1.0/api/user/WebLogin", {
            "phone": "18888888888",
            "password": hash.md5(hash.md5("ZHYQ2022").digest().hex() + t).digest().hex(),
            "t": t,
        })
        assert.equal(result.code, "200");
        assert.equal(result.data.id, 2);
        assert.equal(result.data.role, "超级管理员");
        assert.equal(result.data.edited_password, true);
    });


    it("创建配置", function() {
        var result = httpPost("POST", "/v1.0/api/config/Create", {
            "name":"测试名称",
            "key":"test_name",
            "value":"1",
            "value_explain":"",
            hide:true
        })
        assert.equal(result.code, "200");
    });

    it("配置列表", function() {
        var result = httpPost("GET", "/v1.0/api/config/List", {
        })
        assert.equal(result.code, "200");
        assert.equal(result.data.list.length, 4);
    });

    it("获取配置信息", function() {
        var result = httpPost("GET", "/v1.0/api/config/Get?key=test_name", {
        })
        assert.equal(result.code, "200");
        assert.equal(result.data.name, "测试名称");
    });

    //更改有效时间 职工审批
    it("修改配置信息", function() {
        var result = httpPost("POST", "/v1.0/api/config/Update", {
            "id":4,
            "value":"5",
            "name":"审批有效期",
            "hide":false,
        })
        assert.equal(result.code, "200");
    });

    it("配置列表", function() {
        var result = httpPost("GET", "/v1.0/api/config/List", {
        })

        console.error("配置列表 ", result)
        assert.equal(result.code, "200");
        assert.equal(result.data.list.length, 4);
    });

    it("创建职工审批 ", function () {
        var result = httpPost("POST", "/v1.0/api/staffRecord/Create", {
            name :"张三明",
            gender:"男",
            phone:"15678967654",
            role:"职工",
            department:"肛肠科",
            staff_ic:"1589261",
            staff_hash:"12464657",
            staff_attachments:JSON.stringify([111,2222,333]),
            created_by:"张老三"
        })
        assert.equal(result.code, "200");
        assert.equal(result.msg, "success");
        var result1 = httpPost("POST", "/v1.0/api/staffRecord/Create", {
            name :"张三",
            gender:"女",
            phone:"15688887654",
            department:"内科",
            role:"职工",
            staff_ic:"1500261",
            staff_hash:"127864657",
            staff_attachments:JSON.stringify([1121,22322,3343]),
            created_by:"张老三"
        })
        assert.equal(result1.code, "200");
        assert.equal(result1.msg, "success");
    });

    it("职工审批列表", function() {

        var result = httpPost("POST", "/v1.0/api/staffRecord/List", {
        })
        console.error("职工审批列表 ",result)
        assert.equal(result.code, "200");
        assert.equal(result.msg, "success");
        assert.equal(result.data.list.length,2);
    })

    it("职工通过审批", function() {
        var result = httpPost("POST", "/v1.0/api/staffRecord/Pass", {
            id:10002,
        })

        assert.equal(result.code, "200");
        assert.equal(result.msg, "success");
        assert.equal(result.data.id,10002);
    });

    it("职工审批列表", function() {

        var result = httpPost("POST", "/v1.0/api/staffRecord/List", {
            "status":"已通过"
        })
        console.error("职工审批列表1 ",result)
        assert.equal(result.code, "200");
        assert.equal(result.msg, "success");
        assert.equal(result.data.list.length,1);
    });



});

require('test').run();